<template>
  <div class="popular">
    <div class="newText">最近流行</div>
    <div class="all" @click="liuxing">全部</div>
    <div class="Pbox">
      <div
        v-for="(item, index) in title1"
        class="PPbox"
        :data-cookid="cookid[index]"
      >
        <img :src="img1[index]" alt="" class="img" @click="myselect" />
        <div class="title1" @click="myselect">{{ item }}</div>
        <div class="user">{{ username[index] }}</div>
        <div class="browse">{{ browse[index] }} 浏览记录</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      title1: [],
      img1: [],
      browse: [],
      username: [],
      cookid: [],
    };
  },
  async mounted() {
    var img1 = [];
    var title1 = [];
    var browse = [];
    var username = [];
    var cookid = [];
    this.$axios("/zztz/popular").then((res) => {
      // console.log(res.data);
      res.data.map((el) => {
        img1.push(el.img);
        title1.push(el.title);
        browse.push(el.浏览次数);
        username.push(el.username);
        cookid.push(el.cookid);
      });
      this.title1 = title1;
      this.img1 = img1;
      this.browse = browse;
      this.username = username;
      this.cookid = cookid;
    });
  },
  methods: {
    myselect(e) {
      // console.log(e.target.parentNode.dataset);
      this.$router.push({
        path: `/menudetail/${e.target.parentNode.dataset.cookid}`,
      });
    },
    liuxing() {
      this.$router.push({
        path: `/caidan/centerpop`,
      });
    },
  },
};
</script>

<style scoped="scoped">
.popular {
  width: 490px;
  /* height: 500px; */
  position: absolute;
  left: 156px;
  top: 513px;
  overflow: hidden;
}
.newText {
  font-size: 20px;
  font-weight: 700;
  color: #c0ae7d;
}
.all {
  color: #dd3915;
  position: absolute;
  left: 100px;
  top: 5px;
  cursor: pointer;
}
.all:hover {
  background-color: #dd3915;
  color: white;
}
.Pbox {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}
.PPbox {
  margin-top: 40px;
  width: 235px;
  height: 219px;
  /* background-color: palegreen; */
  border: 1px solid #f3f3f3;
}
.PPbox .img {
  width: 235px;
  height: 138px;
  cursor: pointer;
}
.PPbox .img:hover {
  opacity: 0.8;
}
.title1 {
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  margin: 8px;
  text-align: center;
  cursor: pointer;
}
.title1:hover {
  color: orangered;
}
.user {
  display: inline-block;
  margin-left: 50px;
  margin-right: 20px;
  cursor: pointer;
}
.user:hover {
  color: orangered;
}
.browse {
  display: inline-block;
  color: #a5a7a6;
  font-size: 12px;
}
</style>